	</body>
	<script src="<{STATIC_SERVER}>/layui/layui.all.js"></script>
	<script>
		$(function (){
			//更改导航选中状态
			$(".layui-nav-item").click(function (){
				$(".layui-nav-item").removeClass("layui-nav-itemed");
				if (! $(this).hasClass("layui-nav-itemed")) {
					$(this).addClass("layui-nav-itemed");
				} else {
					$(this).removeClass("layui-nav-itemed");
					$(this).find("dd").removeClass("layui-this");
				}
			})
			
			//获取服务器时间
			get_system_time();
			get_system_info();
		})
		var system_info = system_time = system_holiday = 0;
		var token = "<{$token}>";
		//获取系统时间
		var time = <{round(microtime(true) * 1000)}>;
		var n = t = 0; 
		function get_system_time() {
			//防止用户退出继续请求
			if (system_time >= 0) {
				t = new Date(time);
				n = (t.getHours() < 10 ? "0" :"") + t.getHours() + ":" + (t.getMinutes() < 10 ? "0" :"") + t.getMinutes() + ":" + (t.getSeconds() < 10 ? "0" :"") + t.getSeconds();
				$("#xinsu-system-time").html(n);
				time += 1000;
				system_time = setTimeout("get_system_time();", 1000);
			}
		}
		
		//获取系统信息
		function get_system_info() {
			//防止用户退出继续请求
			if (system_info >= 0) {
				var url = "/index/get_system_info";
				http_request_post(url, "", function(res) {
					var result = res.data;
					$("#xinsu-num").html(result.message);
					if (result.zhishu != "") {
						$("#xinsu-zhishu").html(result.zhishu);
					}
					$("#xinsu-holiday").html(result.holiday);
					if (result.holiday == "休市") {
						system_holiday = 1;
					} else {
						system_holiday = 0;
					}
					system_info = setTimeout("get_system_info();", 1000);
				});
			}
		}
		
		//退出登录
		function logout() {
			layer.confirm('您确定要退出？', {icon: 3}, function () {
				stock = system_info = -1
				var url = "/user/logout";
				layer.closeAll();
				http_request_post(url, null, function(res) {
					layer.msg(res.msg, {icon: 1, time: 800}, function () {
						//跳转到登录页面
						location.href = "/user/login";
					});
				});
			});
		}
		
		//提交表单
        var sub = 0;
		$("form").submit(function () {
			//判断提交方式：get-搜索专用，post-保存专用
			var method = $(this).attr("method");
			if (method == "post") {
				//保存专用
				var rmsg = "";
				var data = $(this).serialize();
				if ("<{$common_info['action']}>" == "bull") {
					var msg = "您是否确定以上交易？";
					var bull_type = $("input[name='bull_type']:checked").val();
					var price_type = $("input[name='price_type']:checked").val();
					
					//股票类型
					if (bull_type == 1) {
						rmsg += "融资";
					} else {
						rmsg += "融券";
					}
					
					//交易类型
					if (price_type == 0) {
						rmsg += "市价";
					} else {
						rmsg += "限价";
					}
					rmsg += "委托处理成功！";
				} else {
					var msg = "您是否确执行该操作？";
				}
				data += '&token='+token;
				layer.confirm(msg, {icon: 3}, function () {
                    sub += 1;
                    layer.closeAll();
                    if (sub == 1) {
                        http_request_post("", data, function (result) {
                            if (rmsg == "") {
                                layer.msg(result.msg, {icon:1, time:800}, function (){
                                    if (result.data != "") {
                                        location.href = result.data;
                                    } else {
                                        location.reload();
                                    }
                                });
                            } else {
                                layer.alert(rmsg, {icon:1, closeBtn:0}, function(){
                                    if (result.data != "") {
                                        location.href = result.data;
                                    } else {
                                        location.reload();
                                    }
                                });
                            }
                        });
                    }
				});
				return false;
			} else {
				//搜索专用
				var data = $(this).serializeArray();
				var	url = "/<{$common_info.controller}>/<{$common_info.action}>";
				$.each(data, function(key, val) {
					if (val.value == "") {
						url += "/0";
					} else {
						url += "/" + val.value;
					}
				});
				location.href = url;
				return false;
			}
		})
		
		//股票K线图弹出框
		$('.xinsu-stock-figure').click(function(){
			var data = $(this).attr("data");
			layer.open({ 
				type: 1,
				title: '股票代码：' + data +' K线图',
				area: ['550px', '400px'],
				shadeClose: true,
				content: '<div class="layui-tab layui-tab-card" style="margin:0; height:99%;"><ul class="layui-tab-title"><li class="layui-this">分时线</li><li>日K线</li><li>周K线</li><li>周K线</li></ul><div class="layui-tab-content" style="height: 100px;"><div class="layui-tab-item layui-show"><img style="width:100%" src="http://image2.sinajs.cn/newchart/min/n/'+data+'.gif"></div><div class="layui-tab-item"><img  style="width:100%" src="http://image2.sinajs.cn/newchart/daily/n/'+data+'.gif"></div><div class="layui-tab-item"><img  style="width:100%" src ="http://image2.sinajs.cn/newchart/weekly/n/'+data+'.gif"></div><div class="layui-tab-item"><img  style="width:100%" src ="http://image2.sinajs.cn/newchart/monthly/n/'+data+'.gif"></div></div></div>'
			});
		});
		
		//通用post请求
		function http_request_post(url, data, callback) {
			if (url != "") {
				url = url;
			}
			$.ajax({
				type : 'post',  
				url : url,
				dataType : 'json',
				data : data,
				success : function(repones) {
					if (repones.status == 1) {
						if (typeof callback === "function") {
							callback(repones);
							return false;
						} else {
							layer.msg('请求加载数据失败，请重新加载');
						}
					} else if (repones.status == 2) {
						stock = system_info = -1
						layer.msg(repones.msg, {time:800}, function() {
							location.href = "/user/login";
						});
						return false;
					} else if (repones.status == 0) {
						token = repones.token;
						layer.msg(repones.msg);
						stock = system_info = -1
						return false;
					} else {
						layer.msg(repones.msg);
						stock = system_info = -1
						return false;
					}
				},
				error : function () {
					layer.load(1, {shade: [0.1,'#fff'], time:500}, function(){
						location.reload();
					});
					return false;
				}
			});
			return false;
		}
	</script>
</html>